package com.cdx.dxmall.memeber.controller;

import com.cdx.dxmall.common.utils.PageUtils;
import com.cdx.dxmall.common.utils.R;
import com.cdx.dxmall.memeber.entity.MemberEntity;
import com.cdx.dxmall.memeber.feign.CouponFeignService;
import com.cdx.dxmall.memeber.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;



/**
 * 会员
 *
 * @author chedx
 * @email chedx@gmail.com
 * @date 2020-12-30 11:40:04
 */
@RefreshScope
@RestController
@RequestMapping("memeber/member")
public class MemberController {
    @Autowired
    private MemberService memberService;

    @Resource
    private CouponFeignService couponFeignService;

    @GetMapping("/coupons/list")
    public R getCoupons() {
        R r = couponFeignService.getMemebersCoupons();
        return r;
    }

    @Value("${coupous.user.name}")
    private String username ;
    @Value("${coupous.user.age}")
    private Integer userage;

    @GetMapping("test")
    public R test() {
        return R.ok().put("name",username).put("age",userage);
    }




    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = memberService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		MemberEntity member = memberService.getById(id);

        return R.ok().put("member", member);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody MemberEntity member){
		memberService.save(member);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody MemberEntity member){
		memberService.updateById(member);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		memberService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
